const state = {
  token: uni.getStorageSync('token') || '',
  pageData: uni.getStorageSync('pageData') || {},
  userinfo: uni.getStorageSync('userinfo') || {},
}

const mutations = {
  set_token(state, data) {
    state.token = data
  },
  set_pageData(state, data) {
    state.pageData = data
  },
  set_userinfo(state, data) {
    state.userinfo = data
  },
}

const actions = {
  on_token({ commit }, data) {
    commit('set_token', data)
    uni.setStorageSync('token', data)
  },
  on_pageData({ commit }, data) {
    commit('set_pageData', data)
    uni.setStorageSync('pageData', data)
  },
  on_userinfo({ commit }, data) {
    commit('set_userinfo', data)
    uni.setStorageSync('userinfo', data)
  },
}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
}
